<script setup>
import { defineEmits, defineProps, ref, watch } from 'vue'
import axios from '@/util/axios'
import { getServerUrl } from '@/util/axios'

const emit = defineEmits(['update:modelValue'])
const handleClose = () => {
  emit('update:modelValue', false)
}
const props = defineProps({
  id: {
    type: Number,
    default: -1,
    required: true
  }
})

watch(() => props.id, () => {
  if (props.id !== -1) {
    initOrderDetailData(props.id)
  }
})
const tableData = ref([])
const initOrderDetailData = async (id) => {
  const res = await axios.get(`admin/orderDetail/list/${id}`)
  tableData.value  = res.data.list
}
const baseUrl = getServerUrl()
</script>

<template>
  <el-dialog
    model-value="dialogVisible"
    title="订单商品详情"
    width="40%"
    @close="handleClose"
  >
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column prop="goodsPic" label="商品图片">
        <template v-slot="scope">
          <img :src="baseUrl+'image/product/'+scope.row.goodsPic" width="80" height="80">
        </template>
      </el-table-column>
      <el-table-column prop="goodsName" label="商品名称"></el-table-column>
      <el-table-column prop="goodsPrice" label="商品价格" width="100"></el-table-column>
      <el-table-column prop="goodsNumber" label="商品数量" width="100"></el-table-column>
    </el-table>
  </el-dialog>
</template>

<style lang="scss" scoped>

</style>
